package schooltg.core.persist.dao.impl;

import org.hibernate.criterion.Restrictions;
import schooltg.core.data.Education;
import schooltg.core.persist.dao.EducationDao;
import schooltg.core.persist.entity.EducationPO;
import mtons.modules.annotation.Repository;
import mtons.modules.persist.impl.BaseRepositoryImpl;
import org.hibernate.Query;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.Map;
import java.util.Set;


/**
 * Created by liuyangfx on 16-4-25.
 */
@Repository(entity = EducationPO.class)
public class EducationDaoImpl extends BaseRepositoryImpl<EducationPO> implements EducationDao {

    @Override
    public EducationPO getEducationByUserId(long id) {
        return findUniqueBy("userId", id);
    }

    @Override
    public void insertEducation(Education education) {
        EducationPO po = new EducationPO();
        BeanUtils.copyProperties(education, po);
        save(po);
    }

    @Override
    public void saveOrUpdateEducation(Education education) {

        saveOrUpdate(education);
    }

    @Override
    public void updateEducation(Education education) {
        Query query = createSQLQuery("update stg_education set college = ? ,profession = ? where user_id =  ?");
        query.setString(0,education.getCollege());
        query.setString(1,education.getProfession());
        query.setLong(2,education.getUserId());
        query.executeUpdate();
    }

    @Override
    public List<EducationPO> getEducationByUserIds(Set<Long> ids) {
        return find(Restrictions.in("userId", ids));

    }
}
